package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CLinePitDao;
import com.hongxun.modules.csg.entity.CLinePitEntity;
import com.hongxun.modules.csg.service.CLinePitService;



@Service("cLinePitService")
public class CLinePitServiceImpl implements CLinePitService {
	@Autowired
	private CLinePitDao cLinePitDao;
	
	@Override
	public CLinePitEntity queryObject(String guid){
		return cLinePitDao.queryObject(guid);
	}
	
	@Override
	public List<CLinePitEntity> queryList(Map<String, Object> map){
		return cLinePitDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cLinePitDao.queryTotal(map);
	}
	
	@Override
	public void save(CLinePitEntity cLinePit){
		if(cLinePit.getGuid()==null||cLinePit.getGuid().equals("")) {
			cLinePit.setGuid(UUID.randomUUID().toString());
		}
		cLinePitDao.save(cLinePit);
	}
	
	@Override
	public void update(CLinePitEntity cLinePit){
		cLinePitDao.update(cLinePit);
	}
	
	@Override
	public void delete(String guid){
		cLinePitDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cLinePitDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CLinePitEntity> entities) {
		for (CLinePitEntity d : entities) {
			if (d.getLPDatastate().equals("删除")) {
				cLinePitDao.delete(d.getGuid());
			} else {
				CLinePitEntity cLinePitEntity = cLinePitDao.queryObject(d.getGuid());
				if (cLinePitEntity == null) {
					cLinePitDao.save(d);
				} else {
					cLinePitDao.update(d);
				}
			}
		}
	}
	
}
